<template>
  <div id="lastContain">
    <!-- 菜单部分 -->
    <div class="myMenu">
      <div
        class="myMenu-item"
        v-for="(item, index) in myMenu"
        :class="{ isChecked: item.isChecked }"
        :key="index"
        @click="handleMenuClick(item)"
      >
        {{ item.title }}
      </div>
    </div>
    <!-- 动态组件部分 -->
    <div class="components-contain">
      <template v-for="(item, index) in allComponents" :key="index">
        <component :is="item"></component>
      </template>
    </div>
  </div>
</template>

<script>
import { myMixin } from "./util/myMixin";
import { myMenu } from "./util/myMenu";
export default {
  mixins: [myMixin],
  data() {
    return {
      myMenu,
      allComponents: [],
    };
  },
  mounted() {
    myMenu.forEach((ev) => {
      if (ev.isChecked) {
        this.allComponents.push(ev.value);
      }
    });
  },
  methods: {
    handleMenuClick(item) {
      console.log("item", item);
      // 选中状态
      if (!item.isChecked) {
        myMenu.forEach((ev) => {
          if (item.multual.includes(ev.value)) {
            ev.isChecked = false;
          }
          if (ev.value === item.value) {
            ev.isChecked = true;
          }
        });
      } else {
        myMenu.forEach((ev) => {
          if (ev.value === item.value) {
            ev.isChecked = false;
          }
        });
      }

      let allMenus = [];
      myMenu.forEach((ev) => {
        if (ev.isChecked) {
          allMenus.push(ev.value);
        }
      });
      this.allComponents = allMenus;
    },
  },
};
</script>

<style scoped>
#lastContain {
  width: 100%;
  height: 100%;
  background: rgb(63, 80, 152);
}
.myMenu {
  width: 120px;
  height: 50px;
  position: absolute;
  top: 20px;
  left: 20px;
}
.myMenu-item {
  width: 100%;
  height: 40px;
  text-align: center;
  line-height: 40px;
  color: rgb(174, 174, 174);
  font-size: 24px;
  margin-bottom: 14px;
  cursor: pointer;
}
.isChecked {
  color: white;
  text-shadow: 2px 2px 2px rgb(124, 124, 124);
}
.components-contain {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
</style>
